package cn.vivi.common.util;

public class Result<T> {

    private Boolean success;
    private String message;
    private T result;

    private Result() {
    }

    private Result(Boolean success, String message, T result) {
        this.success = success;
        this.message = message;
        this.result = result;
    }

    public static Result success() {
        return new Result<>(true, "成功", null);
    }

    public static Result error() {
        return new Result<>(false, "失败", null);
    }

    public static<T> Result<T> success(T obj) {
        return new Result<>(true, "成功", obj);
    }

    public static Result error(String message) {
        return new Result<>(false, message, null);
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    @Override
    public String toString() {
        return "Result{" +
                "success=" + success +
                ", message='" + message + '\'' +
                ", result=" + result +
                '}';
    }
}
